FROM golang:1.22 as builder
WORKDIR /app

ARG SSH_KEY
RUN mkdir -p /root/.ssh && \
    chmod 0700 /root/.ssh && \
    ssh-keyscan codeup.aliyun.com > /root/.ssh/known_hosts && \
    echo "${SSH_KEY}" > /root/.ssh/id_rsa && \
    chmod 600 /root/.ssh/id_rsa
RUN git config --global url."ssh://git@codeup.aliyun.com/".insteadOf "https://codeup.aliyun.com/"

# ENV GOPROXY https://goproxy.cn
ENV GOPRIVATE codeup.aliyun.com

COPY ./go.mod ./go.mod
COPY ./go.sum ./go.sum
RUN go mod download

COPY . .
RUN CGO_ENABLED=0 go build .

FROM alpine:3.10
WORKDIR /app

COPY --from=builder /app/wooha-cache-hub ./wooha-cache-hub
COPY --from=builder /app/config.yaml ./config.yaml
COPY --from=builder /app/scripts ./scripts
COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /etc/localtime


CMD ["./wooha-cache-hub"]